home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / UTILITIE / CONVERSI / 0825C.ZIP / DECODE.ARC / DECODE.C next >
C/C++ Source or Header  |  1980-01-01  |  6KB  |  238 lines

  1. /*                                          */
  2. /*    DECODE -  dBASE II Runtime decoder.      */
  3. /*                                            */
  4. /*    Tom Sivesind                            */
  5. /*  Hennumhagan 14                             */
  6. /*  3408 Tranby                             */
  7. /*  Tlf.: 03-851329                         */
  8. /*                                          */
  9. /*    DeSmet C Development Package            */
  10. /*                                            */
  11.  
  12.  
  13. #define     EOF        -1
  14.  
  15. main(argc,argv)
  16. int        argc;
  17. char    *argv[];
  18. {
  19.  
  20.     int        CurChar, Code;
  21.     char    *InFile, *OutFile;
  22.     char    *Buffer[80], *NewFile[80], *Ptr;
  23.     int        Dotpos = 0;
  24.  
  25.     
  26.     if (argc < 2) {
  27.         printf("\nDECODE - dBASE II RunTime decoder");
  28.         printf("\nYou didn't enter a filename for input.");
  29.         printf("\nProper entry: DECODE filename.ext <CR>\n\n");
  30.         exit(0);
  31.     }
  32.  
  33.     if(!(InFile = fopen(argv[1],"r"))) {
  34.         printf("\n%s???  No such file on the disk.\n\n",argv[1]);
  35.         exit(0);
  36.     }
  37.  
  38.     if((CurChar = getc(InFile)) < 0x7F){
  39.         printf("\n%s  is not a RunTime coded file.\n\n", argv[1]);
  40.         exit(0);
  41.     }
  42.     else
  43.         ungetc(CurChar, InFile);
  44.  
  45.  
  46.     strcpy(NewFile, "");
  47.     Ptr = strcpy(Buffer, argv[1]);
  48.     while (*Ptr++ != '.') Dotpos++;
  49.     strncat(NewFile, argv[1], Dotpos);
  50.     strcat(NewFile, ".DCD");
  51.  
  52.  
  53.     if(!(OutFile = fopen(NewFile, "w"))) {
  54.         printf("\nCannot create: %s\n\n", OutFile);
  55.         exit(0);
  56.     }
  57.  
  58.     printf("\nDECODE RunTime Decoder.  Tom Sivesind, 1985.\n");
  59.     printf("Input File:  %s \n", argv[1]);
  60.     printf("Output File: %s \n", NewFile);
  61.  
  62.     Code = 1;
  63.     
  64.     while ((CurChar = getc(InFile)) != EOF) {
  65.  
  66.         if (CurChar > 0x7F){
  67.             CurChar &= 0x7F;
  68.             CurChar = 0x7F - CurChar;
  69.         }
  70.  
  71.         if (Code == 1){
  72.             switch(CurChar){
  73.                 case 't': fputs("? ", OutFile);
  74.                     break;
  75.                 case 'p': fputs("@ ", OutFile);
  76.                     break;
  77.                 case 'o': fputs("ACCEPT ", OutFile);        
  78.                     break;
  79.                 case 'n': fputs("APPEND ", OutFile);
  80.                     break;
  81.                 case 'm': fputs("BROWSE ", OutFile);
  82.                     break;
  83.                 case 'l': fputs("CALL ", OutFile);
  84.                     break;
  85.                 case 'k': fputs("CANCEL ", OutFile);
  86.                     break;
  87.                 case 'z': fputs("CASE ", OutFile);
  88.                     break;
  89.                 case 'j': fputs("CHANGE ", OutFile);
  90.                     break;
  91.                 case 'i': fputs("CLEAR ", OutFile);
  92.                     break;
  93.                 case 'c': fputs("CONTINUE ", OutFile); 
  94.                     break;
  95.                 case 'h': fputs("COPY ", OutFile);
  96.                     break;
  97.                 case 'g': fputs("COUNT ", OutFile);
  98.                     break;
  99.                 case 'f': fputs("CREATE ", OutFile);
  100.                     break;
  101.                 case 'e': fputs("DELETE ", OutFile);
  102.                     break;
  103.                 case 'd': fputs("DISPLAY ", OutFile);
  104.                     break;
  105.                 case '|': fputs("DO ", OutFile);
  106.                     break;
  107.                 case 'v': fputs("DO CASE ", OutFile);        
  108.                     break;
  109.                 case 'w': fputs("DO WHILE ", OutFile);
  110.                     break;
  111.                 case 'b': fputs("EDIT ", OutFile);
  112.                     break;
  113.                 case 'a': fputs("EJECT ", OutFile);
  114.                     break;
  115.                 case '~': fputs("ELSE ", OutFile);
  116.                     break;
  117.                 case 'x': fputs("ENDCASE ", OutFile);
  118.                     break;
  119.                 case '{': fputs("ENDDO ", OutFile); 
  120.                     break;
  121.                 case '}': fputs("ENDIF ", OutFile);
  122.                     break;
  123.                 case '`': fputs("ERASE ", OutFile);
  124.                     break;
  125.                 case 0x5E: fputs("FIND ", OutFile);
  126.                     break;
  127.                 case '_': fputs("GO ", OutFile);
  128.                     break;
  129.                 case ']': fputs("HELP ", OutFile);
  130.                     break;
  131.                 case 0x7F: fputs("IF ", OutFile);        
  132.                     break;
  133.                 case '\\': fputs("INDEX ", OutFile);
  134.                     break;
  135.                 case '[': fputs("INPUT ", OutFile);
  136.                     break;
  137.                 case 'Z': fputs("INSERT ", OutFile);
  138.                     break;
  139.                 case 'Y': fputs("JOIN ", OutFile);
  140.                     break;
  141.                 case 'X': fputs("LIST ", OutFile);
  142.                     break;
  143.                 case 'W': fputs("LOAD ", OutFile);
  144.                     break;
  145.                 case 'V': fputs("LOCATE ", OutFile); 
  146.                     break;
  147.                 case 'U': fputs("LOOP ", OutFile);
  148.                     break;
  149.                 case 'T': fputs("MODIFY ", OutFile);
  150.                     break;
  151.                 case 'y': fputs("OTHERWISE ", OutFile);
  152.                     break;
  153.                 case 'S': fputs("PACK ", OutFile);
  154.                     break;
  155.                 case 'R': fputs("POKE ", OutFile);
  156.                     break;
  157.                 case 'Q': fputs("QUIT ", OutFile);
  158.                     break;
  159.                 case 'P': fputs("READ ", OutFile);
  160.                     break;
  161.                 case 'O': fputs("RECALL ", OutFile);        
  162.                     break;
  163.                 case 'N': fputs("REINDEX ", OutFile);
  164.                     break;
  165.                 case 's': fputs("RELEASE ", OutFile);
  166.                     break;
  167.                 case 'M': fputs("REMARK ", OutFile);
  168.                     break;
  169.                 case 'L': fputs("RENAME ", OutFile);
  170.                     break;
  171.                 case 'K': fputs("REPLACE ", OutFile);
  172.                     break;
  173.                 case 'J': fputs("REPORT ", OutFile); 
  174.                     break;
  175.                 case 'I': fputs("RESET ", OutFile);
  176.                     break;
  177.                 case 'H': fputs("RESTORE ", OutFile);
  178.                     break;
  179.                 case 'r': fputs("RETURN ", OutFile);
  180.                     break;
  181.                 case 'G': fputs("SAVE ", OutFile);
  182.                     break;
  183.                 case 'q': fputs("SELECT ", OutFile);
  184.                     break;
  185.                 case 'F': fputs("SET ", OutFile);        
  186.                     break;
  187.                 case 'E': if((CurChar = getc(InFile)) == 'N'){
  188.                                 fputs("E", OutFile);
  189.                                 ungetc(CurChar, InFile);
  190.                                 break;
  191.                           }
  192.                           fputs("SKIP ", OutFile);
  193.                     break;
  194.                 case 'D': fputs("SORT ", OutFile);
  195.                     break;
  196.                 case 'u': fputs("STORE ", OutFile);
  197.                     break;
  198.                 case 'C': fputs("SUM ", OutFile);
  199.                     break;
  200.                 case 'B': fputs("TEXT ", OutFile);
  201.                     break;
  202.                 case 'A': fputs("TOTAL ", OutFile);
  203.                     break;
  204.                 case '@': fputs("UNLOCK ", OutFile);
  205.                     break;
  206.                 case '?': fputs("UPDATE ", OutFile); 
  207.                     break;
  208.                 case '>': fputs("USE ", OutFile);
  209.                     break;
  210.                 case '=': fputs("WAIT ", OutFile);
  211.                     break;
  212.                              
  213.                    default: if (CurChar != 0x1A){
  214.                                fputs("*** UNKNOWN CODE: <", OutFile);
  215.                                putc(CurChar, OutFile);
  216.                              fputs("> ", OutFile);
  217.                          }
  218.                     break;    
  219.                 }
  220.         }
  221.         else 
  222.             putc(CurChar, OutFile);
  223.         
  224.         if (CurChar == '\n') 
  225.             Code = 1;
  226.         else 
  227.             Code = 0;
  228.     }
  229.  
  230.     fclose(InFile);
  231.     fclose(OutFile);
  232.     printf("Successful decode.");
  233. }
  234.  
  235.  
  236. /* End Of DECODE */
  237.